package models

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

// 短链表

type Link struct {
	ID          string    `gorm:"primaryKey;type:varchar(36);not null;" json:"id"`
	LinkUrl     string    `gorm:"column:link;type:varchar(255);default:''" json:"linkUrl"`
	LinkCode    string    `gorm:"column:link_code;type:varchar(255);default:''" json:"linkCode"`
	LinkType    string    `gorm:"column:link_type;type:varchar(255);default:''" json:"linkType"`
	LinkName    string    `gorm:"column:link_name;type:varchar(255);default:''" json:"linkName"`
	Post        string    `gorm:"column:post;type:varchar(255);default:''" json:"post"`
	Description string    `gorm:"column:description;type:varchar(255);default:''" json:"description"`
	UserQrCode  string    `gorm:"column:user_qr_code;type:varchar(255);default:''" json:"userQrCode"`
	CreatedAt   time.Time `gorm:"type:timestamp" json:"created_at"`
	UpdatedAt   time.Time `gorm:"type:timestamp" json:"updated_at"`
}

func (w *Link) TableName() string {
	return "link"
}
func (w *Link) BeforeCreate(tx *gorm.DB) (err error) {
	w.ID = uuid.NewString()
	w.CreatedAt = time.Now()
	w.UpdatedAt = time.Now()
	return
}

func (w *Link) BeforeUpdate(tx *gorm.DB) (err error) {
	w.UpdatedAt = time.Now()
	return
}
